Skip to content

Moved logging of incoming messages before processing#3703

Merged
meee1 merged 2 commits intoArduPilot:masterfrom
av-remco:master
Apr 13, 2026
Merged

Moved logging of incoming messages before processing#3703
meee1 merged 2 commits intoArduPilot:masterfrom
av-remco:master

Conversation

@av-remco
Copy link
Copy Markdown
Contributor

see issue #3702

Fix moves the SaveToTlog method call before getInfoFromStream, which sends replies to TIMESYNC, MISSION_REQUEST_INT, etc. So not really just a getter, therefore renamed to processInfoFromStream

First time contributing, so open to all comments!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #3702 by ensuring incoming MAVLink packets are written to the telemetry log (.tlog) before any downstream processing that may synchronously send response packets (e.g., TIMESYNC), preventing replies from being logged earlier than the triggering request.

Changes:

  • Moved incoming SaveToTlog(...) call to occur immediately after packet verification and before message processing/handlers.
  • Renamed getInfoFromStream to processInfoFromStream to better reflect side effects (processing + possible responses).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5090 to +5097
// log before any processing that could send response packets (e.g. timesync)
try
{
SaveToTlog(new Span<byte>(buffer));

if (logfile != null)
{
lock (logfile)
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SaveToTlog() performs synchronous file I/O (and allocates via packet.ToArray() inside SaveToTlog) and is now executed while readlock is held. This extends the critical section that blocks other readPacketAsync() callers and can increase receive latency / risk backlog when logging to slow storage. Consider releasing readlock immediately after the packet is verified/resized, then perform tlog write + subsequent processing (including timesync/mission handling) outside the lock so reading can continue while logging/processing occurs.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment on 4926 says Readlock ended here, but it is ended at 5216. Seems like a serious consideration, the exact ordering of logging/processing/packet sequence error check is beyond my scope. Maybe the solution would be to move processInfoFromStream (or parts of it) down, instead of moving SaveToTlog up

Comment thread ExtLibs/ArduPilot/Mavlink/MAVLinkInterface.cs Outdated
av-remco and others added 2 commits April 13, 2026 15:10
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@meee1 meee1 merged commit c290730 into ArduPilot:master Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants